﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.IO;

using Recon.Portal.DataObjects;
using Recon.Portal.Data;

namespace Recon.Portal.Business
{
    public class MenuManager
    {
    public MenuManager()
	{
		//
		// TODO: Add constructor logic here
		//       
	}

    public void populateMenu(Menu menuBar, string roleId, string CustomerID)
        {
            DBFactory db = new DBFactory();
            DataTable dt = db.populateMenu(roleId, CustomerID);
            if (dt != null)
            {
                foreach (DataRow dr in dt.Select("parent_id='0'"))
                {
                    menuBar.Items.Add(
                        new System.Web.UI.WebControls.MenuItem(
                            dr["menu_name"].ToString()
                            , dr["menu_id"].ToString()
                            , ""
                            , dr["menu_link"].ToString()
                            ));
                }

                foreach (DataRow dr in dt.Select("parent_id <>'0'"))
                {
                    menuBar.FindItem(dr["parent_id"].ToString()).ChildItems.Add(
                        new System.Web.UI.WebControls.MenuItem(
                            dr["menu_name"].ToString()
                            , dr["menu_id"].ToString()
                            , ""
                            , dr["menu_link"].ToString()
                            ));
                }
            }
        }

    public List<Recon.Portal.DataObjects.MenuItem> GetMenuForRole(string RoleID)
    {
        DBFactory db = new DBFactory();
        return db.GetMenuForRole(RoleID);
    }

    public List<Recon.Portal.DataObjects.MenuItem> GetAllMenus(bool systemIncluded)
    {
        DBFactory db = new DBFactory();
        return db.GetAllMenus(systemIncluded);
    }
    }
}